<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of admin
 *
 * @author hoquangminh
 */
class Admin_Form_Config extends Zend_Form {
    private $_translate;
    public function init() {
        parent::init();
        $this->_translate = Zend_Registry::get("translate");
        $this->initFields();
    }
    
    public function initFields() {
        $elements = array();
        
        $description = new Zend_Form_Element_Textarea("description");
        $description->setLabel($this->_translate->_("DESCRIPTION"));
        $elements[] = $description;
        
        $banner_image = new MKT_Form_File("banner_image");
        $banner_image->setLabel($this->_translate->_("BANNER"))
                     ->addValidator('Size', false, 10485760)
                     ->addValidator('Extension', false, 'jpg,jpeg,png,gif');
        $elements[] = $banner_image;
        
        $fangate_image = new MKT_Form_File("fangate_image");
        $fangate_image->setLabel($this->_translate->_("FANGATE"))
                      ->addValidator('Size', false, 10485760)
                      ->addValidator('Extension', false, 'jpg,jpeg,png,gif');
        $elements[] = $fangate_image;
        
        $post_point = $this->_addNumericField("post_point", $this->_translate->_("POST_POINT"));
        $elements[] = $post_point;
        
        $comment_point = $this->_addNumericField("comment_point", $this->_translate->_("COMMENT_POINT"));
        $elements[] = $comment_point;
        
        $like_point = $this->_addNumericField("like_point", $this->_translate->_("LIKE_POINT"));
        $elements[] = $like_point;
        
        $share_point = $this->_addNumericField("vote_point", $this->_translate->_("VOTE_POINT"));
        $elements[] = $share_point;
        
        $background_color = new Zend_Form_Element_Hidden("background_color");
        $background_color->setLabel($this->_translate->_("BACKGROUND_COLOR"));
        $elements[] = $background_color;
        
        $update_freq = $this->_addNumericField("update_frequency", $this->_translate->_("UPDATE_FREQUENCY"));
        $elements[] = $update_freq;
        
        $reset_period = new Zend_Form_Element_Radio("reset_period");
        $reset_period->setLabel($this->_translate->_("RESET_PERIOD"))
                     ->setMultiOptions(array('w' => 'Week', 'm' => 'Month'));
        $elements[] = $reset_period;
        
        $id_social_page = new Zend_Form_Element_Hidden("id_social_page");
        $elements[] = $id_social_page;
        
        $this->addElements($elements);
    }
    
    private function _addNumericField($name, $label) {
        $element = new Zend_Form_Element_Text($name);
        $element->setLabel($label)
                ->setRequired()
                ->addValidator(new Zend_Validate_Int());
        return $element;
    }
    
    private function _addHiddenField($name) {
        $element = new Zend_Form_Element_Hidden($name);
        $element->removeDecorator("DtDdWrapper")
                ->removeDecorator("HtmlTag")
                ->removeDecorator("Label");
        return $element;
    }
}

?>
